package cn.zhouchao.org.controller;

import cn.zhouchao.org.service.IShopAuditLogService;
import cn.zhouchao.org.domain.ShopAuditLog;
import cn.zhouchao.org.query.ShopAuditLogQuery;
import cn.zhouchao.basic.util.AjaxResult;
import cn.zhouchao.basic.util.PageList;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopAuditLog")
public class ShopAuditLogController {
    @Autowired
    public IShopAuditLogService shopAuditLogService;


    /**
     * 保存和修改公用的
     * @param shopAuditLog  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null)
                shopAuditLogService.update(shopAuditLog);
            else
                shopAuditLogService.add(shopAuditLog);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopAuditLogService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public ShopAuditLog findById(@PathVariable("id")Long id){
        return shopAuditLogService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<ShopAuditLog> findAll(){
        return shopAuditLogService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<ShopAuditLog> queryByPage(@RequestBody ShopAuditLogQuery query){
        return shopAuditLogService.queryByPage(query);
    }

    /**
     * 批量删除多个对象
     * 携带的时ids集合，作为对象放在RequestBody请求体中
     * 故与删除不同，就不在路径上+参数，而是通过请求体携带对象（多个）
     * @param ids
     * @return
     */
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        shopAuditLogService.batchDelete(ids);
        return AjaxResult.me().success();
    }
}
